package com.young.common.query;

import java.util.Map;

/**
 * @description：
 * @author: yangyahui01
 * @date: 11/28/24 4:43 PM
 */
public final class QueryBuilder {
    private static final int DEFAULT_PAGE_SIZE = 20;
    private Query query = new Query();
    private boolean completed;

    protected QueryBuilder() {
        this.query.pageSize = 20;
        this.query.page = 1;
    }

    public static QueryBuilder page(int page) {
        QueryBuilder builder = new QueryBuilder();
        builder.query.page = page;
        return builder;
    }

    public static QueryBuilder parameter() {
        return page(-1);
    }

    public QueryBuilder put(Map<String, Object> input) {
        if (input != null) {
            this.query.parameters.putAll(input);
        }

        return this;
    }

    public QueryBuilder put(String name, Object value) {
        if (name != null) {
            this.query.parameters.put(name, value);
        }

        return this;
    }

    public QueryBuilder pageSize(int pageSize) {
        if (this.completed) {
            return this;
        } else {
            this.query.pageSize = pageSize;
            return this;
        }
    }

    public Query build() {
        this.completed = true;
        return this.query;
    }
}
